package com.ruoyi.reim.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.external.domain.ReimDomain;
import com.ruoyi.reim.domain.WorkflowReim;
import com.ruoyi.reim.service.WorkflowReimService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 报销基本信息Controller
 *
 * @author ruoyi
 * @date 2021-07-16
 */
@RestController
@RequestMapping("/workflow/reim")
public class WorkflowReimController extends BaseController
{
    @Autowired
    private WorkflowReimService workflowReimService;

    /**
     * 查询审批详情
     * @param id
     * @return
     */
    @GetMapping(value = "/detail/{id}")
    public AjaxResult selectApproveDetail(@PathVariable("id") String id){
        return AjaxResult.success(workflowReimService.selectApproveDetail(id));
    }

    /**
     * 新增报销
     * @return
     */
    @RequestMapping("/process")
    public AjaxResult reim(@RequestBody ReimDomain reimDomain){
        return AjaxResult.success(workflowReimService.reim(reimDomain));
    }

    /**
     * 查询报销基本信息列表
     */
    //@PreAuthorize("@ss.hasPermi('system:reim:list')")
    @GetMapping("/list")
    public TableDataInfo list(WorkflowReim workflowReim)
    {
        startPage();
        List<WorkflowReim> list = workflowReimService.selectWorkflowReimList(workflowReim);
        return getDataTable(list);
    }

    /**
     * 导出报销基本信息列表
     */
    //@PreAuthorize("@ss.hasPermi('system:reim:export')")
    @Log(title = "报销基本信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WorkflowReim workflowReim)
    {
        List<WorkflowReim> list = workflowReimService.selectWorkflowReimList(workflowReim);
        ExcelUtil<WorkflowReim> util = new ExcelUtil<WorkflowReim>(WorkflowReim.class);
        return util.exportExcel(list, "reim");
    }

    /**
     * 获取报销基本信息详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:reim:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(workflowReimService.selectWorkflowReimById(id));
    }

    /**
     * 新增报销基本信息
     */
    //@PreAuthorize("@ss.hasPermi('system:reim:add')")
    @Log(title = "报销基本信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WorkflowReim workflowReim)
    {
        return toAjax(workflowReimService.insertWorkflowReim(workflowReim));
    }

    /**
     * 修改报销基本信息
     */
    //@PreAuthorize("@ss.hasPermi('system:reim:edit')")
    @Log(title = "报销基本信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorkflowReim workflowReim)
    {
        return toAjax(workflowReimService.updateWorkflowReim(workflowReim));
    }

    /**
     * 删除报销基本信息
     */
    //@PreAuthorize("@ss.hasPermi('system:reim:remove')")
    @Log(title = "报销基本信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(workflowReimService.deleteWorkflowReimByIds(ids));
    }
}
